﻿Imports System.Data.SqlClient

Module Sales_Utilities

    Public Function GetProspectName(ByVal ProspectID As Integer) As String
        Try
            Dim cmd As New SqlCommand("Select IsNull(Name,N'') From Prospects Where SNo=" & ProspectID, cnn)
            Dim ProspectName As String

            cnn.Open()
            ProspectName = CStr(cmd.ExecuteScalar)
            cnn.Close()

            Return ProspectName
        Catch ex As Exception
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Function

    Sub PrintSlip(ByVal SlipNo As String, ByVal Abbreviation As String)
        Try
            Dim dap1 As New SqlDataAdapter("Select * From Slips Where SlipNo=@SlipNo", cnn)
            Dim dap2 As New SqlDataAdapter("Select * From SlipsSubs Where SlipNo=@SlipNo", cnn)
            Dim das As New DataSet

            dap1.SelectCommand.Parameters.AddWithValue("@SlipNo", SlipNo)
            'dap2.SelectCommand.Parameters.AddWithValue("@SlipNo", SlipNo)

            cnn.Open()
            dap1.Fill(das, "Slips")
            'dap2.Fill(das, "SlipsSubs")
            cnn.Close()

            'i think its ok
            'ylla al dap tb3 al Slips Btgeeb data bs al Dap2 ma Btgeeb

            Select Case Abbreviation
                Case "PII"
                    Dim rpt As New SlipPUL
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "FAP"
                    Dim rpt As New SlipFAP
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "MON"
                    Dim rpt As New SlipMON
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "MBI"
                    Dim rpt As New SlipMBD
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "PAR"
                    Dim rpt As New SlipPAR
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "MON"
                    Dim rpt As New SlipMON
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "MAC"
                    Dim rpt As New SlipMAC
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "CAR"
                    Dim rpt As New SlipCAR
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "PES"
                    Dim rpt As New SlipPEI
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "FGI"
                    Dim rpt As New SlipFG
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()

                Case "WCA"
                    Dim rpt As New SlipWCA
                    rpt.SetDataSource(das)
                    rptViewer.CrystalReportViewer1.ReportSource = rpt
                    rptViewer.CrystalReportViewer1.RefreshReport()
                    rptViewer.ShowDialog()
                    rpt.Dispose()
            End Select
        Catch ex As Exception
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub
End Module
